﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VirtualMarketProvider.IOC.cs" company="">
//   
// </copyright>
// <summary>
//   The virtual market provider.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using Systemathics.FrameWork;

namespace Systemathics.Providers
{
    public sealed partial class VirtualMarketProvider
    {
        private bool MarketOrderManager(OrderTracker o)
        {
            lock (o)
            {
                if (o.isPending)
                {
                    //var delay = Time.Now - o.SendTime; 
                    // What's happen if you are in virtual mode instead of BackTest with delay ?
                    var lasttime = LastFeeds[o.InstrumentId].Blotter[QuoteLevel.One].Time;
                    var delay = lasttime - o.SendTime;
                    if (delay.TotalMilliseconds > VMParameters.AckDelay)
                    {
                        o.SetisAcknoweldged(true);
                        _EmitOrderStatus(this, new OrderStatusEventArgs(o.Id, OrderStatus.ACK, o.TargetQuantity, o.TargetPrice, o.RemainingQuantity, 0, null) { SendTime = o.SendTime, AckTime = lasttime });
                        return CheckIfMarketExecution(ref o);
                    }
                }
            }
            return false;
        }
    }
}